package com.example.springbott.controller;

import com.example.springbott.aspactJ.OperationName;
import com.example.springbott.bean.BaseRespVo;
import com.example.springbott.bean.MarketCoupon;
import com.example.springbott.bean.MarketCouponUser;
import com.example.springbott.bo.CreateCouponBo;
import com.example.springbott.service.MarketCouponUserService;
import com.example.springbott.vo.CreateCouponVo;
import com.example.springbott.common.CommonData;
import com.example.springbott.service.MarketCpService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author 付常莹
 * @description: TODO
 * @date 2022/11/20 12:10
 * 该Controller用于优惠券管理模块
 */
@RestController
@RequestMapping("/admin/coupon")
@Transactional
public class CouponController {
    @Resource
    MarketCpService marketCpService;

    @Resource
    MarketCouponUserService marketCouponUserService;

    /**
     * 该方法用于展示，查找优惠券
     */

    @RequiresPermissions("admin:coupon:list")
    @RequestMapping("list")
    @OperationName("1")
    public BaseRespVo list(Integer page, Short limit, String name,
                           Short type, Short status, String sort,String order){
       CommonData<MarketCoupon> data =  marketCpService.selectCoupon(page, limit, name, type, status,sort,order);
       return BaseRespVo.ok(data);
    }


    /**
     * 该方法用于新增优惠券
     *该方法有bug
     */
    @RequiresPermissions("admin:coupon:create")
    @RequestMapping("create")
    @OperationName("1")
    public BaseRespVo create(@RequestBody MarketCoupon marketCoupon){
       MarketCoupon data = marketCpService.createCoupon(marketCoupon);
        return BaseRespVo.ok(data);
    }


    /**
     * 该方法用于修改优惠券信息
     */
    @RequiresPermissions("admin:coupon:update")
    @PostMapping("update")
    @OperationName("1")
    public BaseRespVo update(@RequestBody MarketCoupon marketCoupon){
        MarketCoupon data = marketCpService.updateCoupon(marketCoupon);
        return BaseRespVo.ok(data);
    }


    /**
     * 该方法用于删除优惠券
     */
    @RequiresPermissions("admin:coupon:delete")
    @PostMapping("delete")
    @OperationName("1")
    public BaseRespVo delete(@RequestBody MarketCoupon marketCoupon){
        marketCpService.deleteCoupon(marketCoupon);
        return BaseRespVo.ok(null);
    }


    /**
     * 该方法用于展示优惠券详情
     * get
     */
    @RequiresPermissions("admin:coupon:read")
    @GetMapping("read")
    @OperationName("1")
    public BaseRespVo read(Integer id){
        MarketCoupon data= marketCpService.readCoupon(id);
        return BaseRespVo.ok(data);
    }


    /**
     * 该方法同样用于优惠券详情展示
     */
    @RequiresPermissions("admin:coupon:listuser")
    @GetMapping("listuser")
    @OperationName("1")
    public BaseRespVo listuser(Integer page, Integer limit, Integer couponId, Integer userId,Short status, String sort, String order){
        CommonData<MarketCouponUser> data = marketCouponUserService.listUser(page,limit,couponId,userId,status,sort,order);
        return BaseRespVo.ok(data);
    }

}
